﻿using System;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace YRevitJig
{
	[Transaction(TransactionMode.Manual)]
	[Regeneration(RegenerationOption.Manual)]
	public class JigCircle : IExternalCommand
	{
		public Result Execute(ExternalCommandData cmdData, ref string message, ElementSet elements)
		{
			UIDocument activeUIDocument = cmdData.Application.ActiveUIDocument;
			ViewAssist.ViewValidating(activeUIDocument.Document, activeUIDocument.ActiveView);
			XCircleJig xcircleJig = new XCircleJig(activeUIDocument);
			XYZ xyz = xcircleJig.PickCenterPoint("请确定圆中心点:");
			bool flag = xyz == null;
			Result result;
			if (flag)
			{
				xcircleJig.Dispose();
				result = Autodesk.Revit.UI.Result.Succeeded;
			}
			else
			{
				double num = xcircleJig.PickCircleRadius(xyz, "请确定圆上一点：");
				bool flag2 = num == 0.0;
				if (flag2)
				{
					xcircleJig.Dispose();
					result = Autodesk.Revit.UI.Result.Succeeded;
				}
				else
				{
					Transaction transaction = new Transaction(activeUIDocument.Document);
					transaction.Start("CreateCurve");
					Arc arc = Arc.Create(xyz, num, 0.0, Math.PI*2, activeUIDocument.ActiveView.RightDirection, activeUIDocument.ActiveView.UpDirection);
					activeUIDocument.Document.Create.NewDetailCurve(activeUIDocument.ActiveView, arc);
					transaction.Commit();
					xcircleJig.Dispose();
					result = Autodesk.Revit.UI.Result.Succeeded;
				}
			}
			return result;
		}
	}
}
